package com.ruoyi.web.controller.driver;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.driver.domain.TDriverBindVehicle;
import com.ruoyi.driver.service.ITDriverBindVehicleService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 司机绑定车辆Controller
 * 
 * @author ruoyi
 * @date 2024-12-26
 */
@RestController
@RequestMapping("/driver/vehicle")
public class TDriverBindVehicleController extends BaseController
{
    @Autowired
    private ITDriverBindVehicleService tDriverBindVehicleService;

    /**
     * 查询司机绑定车辆列表
     */
    @PreAuthorize("@ss.hasPermi('driver:vehicle:list')")
    @GetMapping("/list")
    public TableDataInfo list(TDriverBindVehicle tDriverBindVehicle)
    {
        startPage();
        List<TDriverBindVehicle> list = tDriverBindVehicleService.selectTDriverBindVehicleList(tDriverBindVehicle);
        return getDataTable(list);
    }

    /**
     * 导出司机绑定车辆列表
     */
    @PreAuthorize("@ss.hasPermi('driver:vehicle:export')")
    @Log(title = "司机绑定车辆", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TDriverBindVehicle tDriverBindVehicle)
    {
        List<TDriverBindVehicle> list = tDriverBindVehicleService.selectTDriverBindVehicleList(tDriverBindVehicle);
        ExcelUtil<TDriverBindVehicle> util = new ExcelUtil<TDriverBindVehicle>(TDriverBindVehicle.class);
        util.exportExcel(response, list, "司机绑定车辆数据");
    }

    /**
     * 获取司机绑定车辆详细信息
     */
    @PreAuthorize("@ss.hasPermi('driver:vehicle:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id)
    {
        return success(tDriverBindVehicleService.selectTDriverBindVehicleById(id));
    }

    /**
     * 新增司机绑定车辆
     */
    @PreAuthorize("@ss.hasPermi('driver:vehicle:add')")
    @Log(title = "司机绑定车辆", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TDriverBindVehicle tDriverBindVehicle)
    {
        return toAjax(tDriverBindVehicleService.insertTDriverBindVehicle(tDriverBindVehicle));
    }

    /**
     * 修改司机绑定车辆
     */
    @PreAuthorize("@ss.hasPermi('driver:vehicle:edit')")
    @Log(title = "司机绑定车辆", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TDriverBindVehicle tDriverBindVehicle)
    {
        return toAjax(tDriverBindVehicleService.updateTDriverBindVehicle(tDriverBindVehicle));
    }

    /**
     * 删除司机绑定车辆
     */
    @PreAuthorize("@ss.hasPermi('driver:vehicle:remove')")
    @Log(title = "司机绑定车辆", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids)
    {
        return toAjax(tDriverBindVehicleService.deleteTDriverBindVehicleByIds(ids));
    }
}
